package com.diandiji.demo.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.jetbrains.annotations.NotNull;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class Note implements Serializable {
    //通过继承Serializable把对象的状态信息通过网络进行传输，或者需要将对象的状态信息持久化，以便将来使用时都需要把对象进行序列化。
    @TableId(type = IdType.AUTO) //指定 笔记编号 为主键，并设置为自增。
    private int notenum;

    @NotNull
    //使用 @NotNull 注解，确保字段不能为 null
    private int userID;

    @NotNull
    private String title;

    @NotNull
    private String text;

    private String img;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") // 格式化日期
    private Date notetime= new Date(); // 创建日期，默认当前时间

    @NotNull
    private String tag;

    @NotNull
    private int areaID;

    public int getNotenum() { return notenum; }
    public void setNotenum(int notenum) { this.notenum = notenum; }



    public int getUserID(){return userID;}
    public void setUserID(int userID) { this.userID = userID; }


    public String getTitle() { return title; }
    public void setTitle(String title) { this.title = title; }

    public String getText(){return text;}
    public void setText(String text) { this.text = text; }

    public String getImg(){return img;}
    public void setImg(String img) { this.img=img; }

    public Date getNotetime(){return notetime;}
    public void setNotetime(Date notetime) { this.notetime = notetime; }

    public String getTag(){return tag;}
    public void setTag(String tag) { this.tag = tag; }

    public int getAreaID(){return areaID;}
    public void setAreaID(int area) { this.areaID = area; }

    // 添加图片 URL 到 img 字段
    public void addImageUrl(String url) {
        if (this.img == null || this.img.isEmpty()) {
            this.img = url;
        } else {
            this.img = this.img + "," + url;
        }
    }

    // 获取所有图片 URL 列表
    public List<String> getImageUrls() {
        if (this.img == null || this.img.isEmpty()) {
            return new ArrayList<>();
        }
        return List.of(this.img.split(","));
    }
}
